package com.ruoyi.web.controller.compensationManagement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.compensationManagement.domain.PositionSettings;
import com.ruoyi.compensationManagement.service.IPositionSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 岗位设置Controller
 * 
 * @author yuan
 * @date 2022-10-05
 */
@RestController
@RequestMapping("/compensationManagement/positionSettings")
public class PositionSettingsController extends BaseController
{
    @Autowired
    private IPositionSettingsService positionSettingsService;

    /**
     * 查询岗位设置列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:list')")
    @GetMapping("/list")
    public AjaxResult list(PositionSettings positionSettings)
    {
        List<PositionSettings> list = positionSettingsService.selectPositionSettingsList(positionSettings);
        return AjaxResult.success(list);
    }

    /**
     * 导出岗位设置列表
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:export')")
    @Log(title = "岗位设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PositionSettings positionSettings)
    {
        List<PositionSettings> list = positionSettingsService.selectPositionSettingsList(positionSettings);
        ExcelUtil<PositionSettings> util = new ExcelUtil<PositionSettings>(PositionSettings.class);
        util.exportExcel(response, list, "岗位设置数据");
    }

    /**
     * 获取岗位设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:query')")
    @GetMapping(value = "/{positionId}")
    public AjaxResult getInfo(@PathVariable("positionId") Long positionId)
    {
        return AjaxResult.success(positionSettingsService.selectPositionSettingsByPositionId(positionId));
    }

    /**
     * 新增岗位设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:add')")
    @Log(title = "岗位设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PositionSettings positionSettings)
    {
        return toAjax(positionSettingsService.insertPositionSettings(positionSettings));
    }

    /**
     * 修改岗位设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:edit')")
    @Log(title = "岗位设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PositionSettings positionSettings)
    {
        return toAjax(positionSettingsService.updatePositionSettings(positionSettings));
    }

    /**
     * 删除岗位设置
     */
    @PreAuthorize("@ss.hasPermi('compensationManagement:positionSettings:remove')")
    @Log(title = "岗位设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{positionIds}")
    public AjaxResult remove(@PathVariable Long[] positionIds)
    {
        return toAjax(positionSettingsService.deletePositionSettingsByPositionIds(positionIds));
    }
}
